unit clsRaveReport;

interface

uses
  Classes, rpRave;

Type
  TRaveReport = class
  private
    FMemStream: TMemoryStream;
    FFileName: String;
    FProjectFileName: String;

    procedure SetFileName(const Value: String);
    procedure SetProjectFileName(const Value: String);

  public
    property FileName: String read FFileName write SetFileName;
    property ProjectFileName: String read FProjectFileName
      write SetProjectFileName;
    Procedure Print(APrintPDF: Boolean = False);
  end;

implementation

uses
  UdmoRaveReport, Forms, SysUtils, RpDefine;

{ TRaveReport }

procedure TRaveReport.Print(APrintPDF: Boolean);
begin
  FMemStream := TMemoryStream.Create;
  try
    with dmoRaveReport do
    begin
      rvProject.Active := False;
      rvProject.ProjectFile := ExtractFilePath(Application.ExeName) +
        'relatorios\' + Self.FProjectFileName;
      if not APrintPDF then
      begin
        rvProject.Engine := rvSystem;
      end
      else
      begin
        rvProject.Engine := rvNDRWriter;
        rvNDRWriter.Stream := FMemStream;
        rvNDRWriter.StreamMode := smUser;
      end;
      rvProject.Active := True;
      rvProject.Execute;
      // Se for imprimir diretamente no PDF
      {if APrintPDF then
        RvRenderPDF.PrintRender(rvNDRWriter.Stream, Self.FFileName);
      }
    end;
  finally

  end;
end;

procedure TRaveReport.SetFileName(const Value: String);
begin
  FFileName := Value;
end;

procedure TRaveReport.SetProjectFileName(const Value: String);
begin
  FProjectFileName := Value;
end;

end.
